class Solution:
    def gcdOfStrings(self, str1: str, str2: str) -> str:
        l1 = len(str1)
        l2 = len(str2)
        if not l1 or not l2:
            return ""
        if l1<l2:
            for i in range(1,l1+1):
                if self.judge_of_str(str1[:i], str2):
                    return str1[:i]
        elif l1>l2:
            for i in range(1,l2+1):
                if self.judge_of_str(str2[:i], str1):
                    return str2[:i]
        elif l1==l2:
            if str1==str2:
                return str1
        return ""

    def judge_of_str(self,s1,s2):
        """
        len(s1) < len(s2)
        判断s1是否能被s2除尽
        """
        l1 = len(s1)
        l2 = len(s2)

        if l2%l1 !=0:
            return False
        mul = l2//l1
        return s1*mul == s2

# print(Solution().gcdOfStrings("ABABAB","ABAB"))
print(Solution().gcdOfStrings("ABcABc","ABc"))
# print(Solution().gcdOfStrings("TAUXXTAUXXTAUXXTAUXXTAUXX","TAUXXTAUXXTAUXXTAUXXTAUXXTAUXXTAUXXTAUXXTAUXX"))